﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Main_Inventory_PurchasedReceivedDisplay : System.Web.UI.Page
{
    string POID = "";
    string transferedid = "";
    string supplier = "";
    string taxgroup = "";
    string trnid = "";
    Datautility DU = new Datautility();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["POID"] != null && Request.QueryString["transferedid"] != null)
        {
            POID = Request.QueryString["POID"].ToString();            
            transferedid = Request.QueryString["transferedid"].ToString();            
            trnid = Request.QueryString["trnid"].ToString();
        }
        if (!IsPostBack)
        {           
           BindPurchaseReceivd();
           BindPurchaseReceivedItems();          
        }
    }
    protected void BindPurchaseReceivd()
    {        
        SqlParameter[] parm = { new SqlParameter("@TRNID",trnid)  };
        DataTable dt = DU.getdatausingprocedure("usp_IVR_DisplayPurchaseReceived", parm);        
        if (dt.Rows.Count > 0)
        {
            
            lblPONumber.Text = dt.Rows[0]["pono"].ToString();
            lblSupplier.Text = dt.Rows[0]["Lname"].ToString();
            lblvouno.Text = dt.Rows[0]["voucherno"].ToString();            
            lblinvno.Text = dt.Rows[0]["invoiceno"].ToString();
            lblmodeofpay.Text = dt.Rows[0]["Modeofpayment"].ToString();
            lblbilref.Text = dt.Rows[0]["bill"].ToString();
            lbldate.Text = dt.Rows[0]["TRNDATE"].ToString();
            lbltaxgroup.Text = dt.Rows[0]["MAINCLASSNAME"].ToString();
            lblmodeofdelivery.Text = dt.Rows[0]["modeofdelivery"].ToString();
            lbldeliverydate.Text = dt.Rows[0]["deliverydate"].ToString();
            lbldocno.Text = dt.Rows[0]["documentnum"].ToString();
            lbltransportname.Text = dt.Rows[0]["vehiclenum"].ToString();
            lblvehicleno.Text = dt.Rows[0]["transportname"].ToString();
            lblpreparedby.Text = dt.Rows[0]["preparedby"].ToString();
            lblcheckedby.Text = dt.Rows[0]["checkedby"].ToString();
            lblauthorizedby.Text = dt.Rows[0]["AUTHRSDSIGNAT"].ToString();
            lblnarration.Text = dt.Rows[0]["narration"].ToString();
            lblremarks.Text = dt.Rows[0]["remarks"].ToString();
            lblInvoiceAmt.Text = Convert.ToDouble(dt.Rows[0]["InvoiceAmount"].ToString()).ToString("N2");
            lblPurchaseReceDate.Text = Convert.ToDateTime(dt.Rows[0]["PurchaseRecDate"].ToString()).ToShortDateString();
            lbltotalgrossamt.Text =Convert.ToDouble(dt.Rows[0]["itemtotal"].ToString()).ToString("N2");
            lbltaxableamt.Text =Convert.ToDouble(dt.Rows[0]["taxableamt"].ToString()).ToString("N2");
            if (dt.Rows[0]["taxamt"].ToString() != "")
            {
                lblvatcst.Text = Convert.ToDouble(dt.Rows[0]["taxamt"].ToString()).ToString("N2");
            }           
            lblroundoffamt.Text = Convert.ToDouble(dt.Rows[0]["RNDOFFAMT"].ToString()).ToString("N2") ;
            lblgrandtotal.Text =Convert.ToDouble(dt.Rows[0]["trntotal"].ToString()).ToString("N2");           
        }
    }
    protected void BindPurchaseReceivedItems()
    {
        SqlParameter[] parareceived = { 
                                       new SqlParameter("@TRNID",trnid)
                                      };
        DataTable dtreceived = DU.getdatausingprocedure("usp_ivr_purchaseReceivedDisplay_by_trnid", parareceived);
        if (dtreceived.Rows.Count > 0)
        {
            for (int i = 0; i < dtreceived.Rows.Count; i++)
            {
                HtmlTableRow row1 = new HtmlTableRow();

                HtmlTableCell cell1 = new HtmlTableCell();
                Label lblitems = new Label();
                lblitems.Text = dtreceived.Rows[i]["Items"].ToString();                               
                cell1.Style.Add("border-right", "1px solid #818181");
                cell1.Style.Add("border-bottom", "1px solid #818181");               
                cell1.Controls.Add(lblitems);

                HtmlTableCell cell2 = new HtmlTableCell();
                Label lblUnitPrice = new Label();
                lblUnitPrice.Text = Convert.ToDouble(dtreceived.Rows[i]["UnitPrice"].ToString()).ToString("N2");
                cell2.Style.Add("border-right", "1px solid #818181");
                cell2.Style.Add("border-bottom", "1px solid #818181");
                cell2.Style.Add("text-align", "right");
                cell2.Controls.Add(lblUnitPrice);

                HtmlTableCell cell3 = new HtmlTableCell();
                Label lblrecqty = new Label();
                lblrecqty.Text = Convert.ToDouble(dtreceived.Rows[i]["ReceivedQty"].ToString()).ToString("N2");
                cell3.Style.Add("border-right", "1px solid #818181");
                cell3.Style.Add("border-bottom", "1px solid #818181");               
                cell3.Style.Add("text-align", "right");
                cell3.Controls.Add(lblrecqty);

                HtmlTableCell cell4 = new HtmlTableCell();
                Label lblsubAmount = new Label();
                lblsubAmount.Text = Convert.ToDouble(dtreceived.Rows[i]["SubAmount"].ToString()).ToString("N2");
                cell4.Style.Add("border-right", "1px solid #818181");
                cell4.Style.Add("border-bottom", "1px solid #818181");               
                cell4.Style.Add("text-align", "right");
                cell4.Controls.Add(lblsubAmount);

                HtmlTableCell cell5 = new HtmlTableCell();
                Label lblSalesTax = new Label();
                if (dtreceived.Rows[i]["SalesTax"].ToString() != "")
                {
                    lblSalesTax.Text = Convert.ToDouble(dtreceived.Rows[i]["SalesTax"].ToString()).ToString("N2");
                }
                cell5.Style.Add("border-right", "1px solid #818181");
                cell5.Style.Add("border-bottom", "1px solid #818181");               
                cell5.Style.Add("text-align", "right");
                cell5.Controls.Add(lblSalesTax);

                HtmlTableCell cell6 = new HtmlTableCell();
                Label lbltaxAmount = new Label();
                if (dtreceived.Rows[i]["SalesTaxAmount"].ToString() != "")
                {
                    lbltaxAmount.Text = Convert.ToDouble(dtreceived.Rows[i]["SalesTaxAmount"].ToString()).ToString("N2");
                }
                cell6.Style.Add("border-right", "1px solid #818181");
                cell6.Style.Add("border-bottom", "1px solid #818181");               
                cell6.Style.Add("text-align", "right");
                cell6.Controls.Add(lbltaxAmount);

                HtmlTableCell cell7 = new HtmlTableCell();
                Label lblFreight = new Label();
                if (dtreceived.Rows[i]["freight"].ToString() != "")
                {
                    lblFreight.Text = Convert.ToDouble(dtreceived.Rows[i]["freight"].ToString()).ToString("N2");
                }
                cell7.Style.Add("border-right", "1px solid #818181");
                cell7.Style.Add("text-align", "right");
                cell7.Style.Add("border-bottom", "1px solid #818181");
                cell7.Controls.Add(lblFreight);

                HtmlTableCell cell8 = new HtmlTableCell();
                Label lblPackaging= new Label();
                lblPackaging.Text = Convert.ToDouble(dtreceived.Rows[i]["Packaging"].ToString()).ToString("N2");
                cell8.Style.Add("text-align", "right");
                cell8.Style.Add("border-right", "1px solid #818181");
                cell8.Style.Add("border-bottom", "1px solid #818181");
                cell8.Controls.Add(lblPackaging);                

                HtmlTableCell cell9 = new HtmlTableCell();
                Label lblInsurance = new Label();
                cell9.Style.Add("border-right", "1px solid #818181");
                lblInsurance.Text = dtreceived.Rows[i]["Insurance"].ToString();
                cell9.Style.Add("text-align", "right");                
                cell9.Style.Add("border-bottom", "1px solid #818181");
                cell9.Controls.Add(lblInsurance);

                HtmlTableCell cell10 = new HtmlTableCell();
                Label lbltotalLandedCost = new Label();
                lbltotalLandedCost.Text = dtreceived.Rows[i]["TotallandedCost"].ToString();
                cell10.Style.Add("text-align", "right");
                cell9.Style.Add("border-right", "1px solid #818181");
                cell10.Style.Add("border-bottom", "1px solid #818181");
                cell10.Controls.Add(lbltotalLandedCost);

                HtmlTableCell cell11 = new HtmlTableCell();
                Label lblServicetax = new Label();
                lblServicetax.Text = dtreceived.Rows[i]["SERVICETAX"].ToString();
                cell11.Style.Add("text-align", "right");
                cell11.Style.Add("border-right", "1px solid #818181");
                cell11.Style.Add("border-bottom", "1px solid #818181");
                cell11.Controls.Add(lblServicetax);

                HtmlTableCell cell12 = new HtmlTableCell();
                Label lblServicetaxAmount = new Label();
                lblServicetaxAmount.Text = dtreceived.Rows[i]["SERVICETAXAMOUNT"].ToString();
                cell12.Style.Add("text-align", "right");
                cell12.Style.Add("border-right", "1px solid #818181");
                cell12.Style.Add("border-bottom", "1px solid #818181");
                cell12.Controls.Add(lblServicetaxAmount);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2); 
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);
                row1.Cells.Add(cell6);
                row1.Cells.Add(cell11);
                row1.Cells.Add(cell12);
                row1.Cells.Add(cell7);
                row1.Cells.Add(cell8);
                row1.Cells.Add(cell9);
                row1.Cells.Add(cell10);
               
                tbl_purReceived.Rows.Add(row1);
                lbltotalitemqty.Text =Convert.ToDouble(dtreceived.Compute("sum(ReceivedQty)", "").ToString()).ToString("N2");
                lblposttaxtotal.Text = Convert.ToDouble(dtreceived.Compute("sum(TotallandedCost)", "").ToString()).ToString("N2");
            }
        }
    }
}
